<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"       
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
 <h:head><title>Advise Update List</title></h:head>
 
 <body>
 	 <ui:composition template="/template/main_template.xhtml">
 	 	 <ui:define name="content">
 	 	 
 	 	 <p:panel id="panel" header="Advise Update List " style="width:95%">  			
		    <h:form id="puListForm">
		    <input type="hidden" name="selectedProjectId" value="#{adviseUpdateBean.selectedProjectId}" />
		    <p:outputPanel id="searchPanel"   styleClass="no-borders">
					<p:focus context="puListForm"/>
					
					<p:growl id="growlForm" showDetail="true" life="3000" autoUpdate="false" /> 
				<p:panelGrid style="width:100%; background-color: lightgrey;" styleClass="no-borders">
					<p:row>
						<p:column style="width:15%;text-align:right; margin-right:5px;vertical-align:middle" id="projectName">
							<p:outputLabel  value="Project Name"/>
						</p:column>
						<p:column style="width:40%;text-align:left;vertical-align:middle">											
							<p:selectOneMenu id="projectList" value="#{adviseUpdateBean.selectedProjectId}"  requiredMessage="Project Name is mandatory"
								 required="true" style="width:100%" for="projectName">  
								<f:selectItems value="#{adviseUpdateBean.projects}"/>
							</p:selectOneMenu>
						</p:column>
						<p:column style="width:15%;text-align:right; margin-right:5px;vertical-align:middle" id="UnitNoLbl">
							<p:outputLabel  value="Unit No"/>
						</p:column>
						<p:column style="width:15%;text-align:left;vertical-align:middle">
							 <p:inputText id="unitTxt" value="#{adviseUpdateBean.unit}"/>
						</p:column>
						<p:column  style="width:15%;text-align:left;vertical-align:middle">
							 <p:commandButton value = "Search" action="#{adviseUpdateBean.searchProject}" ajax="false" process="projectList,unitTxt" update=":puListForm:resultsPanel"/>.
						</p:column>
					</p:row>
				</p:panelGrid>
				<br/>
				</p:outputPanel>
 	 	 	<p:outputPanel id="resultsPanel" rendered = "#{adviseUpdateBean.selectedProjectId != null}" >
 	 	 	
 		 	 	<p:dataTable id="dt" var="dto" value="#{adviseUpdateBean.dtoList}" draggableColumns="true" resizableColumns="false" paginatorPosition="bottom" paginatorAlwaysVisible="false"
 		 	 			paginator="true" rows="10"  rowsPerPageTemplate="5,10,15" tableStyle="width:100%" 
                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} "  >  
                 
    			    <p:column headerText="Unit No" sortBy="#{dto.projectInvetory.unitNo}">  
            			<p:outputLabel  value="#{dto.projectInvetory.unitNo}" />  
        			</p:column>
        			 <p:column headerText="Purchaser Name" sortBy="#{dto.customer.fullName}">  
            			<p:outputLabel  value="#{dto.customer.fullName}" />  
        			</p:column>
        			  <p:column headerText="Selling Price(RM)" sortBy="#{dto.projectInvetory.purchasePrice}" style="text-align:right">          			 
            			<h:outputText  value="#{dto.projectInvetory.purchasePrice}"  style="text-align:right" >
            				<f:convertNumber pattern="#,###,##0.00"   />
            			</h:outputText>  
        			</p:column>
        			 <p:column headerText="Purchased Date" sortBy="#{dto.account.datePurchased}" style="text-align:center">  
            			<h:outputText  value="#{dto.account.datePurchased}" >
            				<f:convertDateTime type="both" locale="ms-my" pattern="#{adviseUpdateBean.dateFormat}" />
            			</h:outputText>  
        			</p:column>
        			 <p:column headerText="Advise Date" sortBy="#{dto.account.adviseSignedDate}" style="text-align:center">  
            			<h:outputText  value="#{dto.account.adviseSignedDate}" >
            				<f:convertDateTime pattern="#{adviseUpdateBean.dateFormat}" ></f:convertDateTime>
            			</h:outputText>    
        			</p:column>
        			<p:column style="width:4%">  
			                <p:commandButton id="selectDTOBtn" update=":dialogForm:dialogPanel" oncomplete="dlg.show()" icon="ui-icon-search" title="View" >  
			                	<f:setPropertyActionListener value="#{dto}" target="#{adviseUpdateBean.selectedDto}" />  
			            </p:commandButton>  
			        </p:column> 
        			
		        </p:dataTable> 
				</p:outputPanel>
				</h:form>
				<h:form id="dialogForm">
				<p:outputPanel id="dialogPanel">
				 <p:dialog id="tDialog" header="Advise Date Update" widgetVar="dlg"
				        modal="true" height="340" width="750"  showEffect="explode"
				        hideEffect="explode">
				        
				        <p:growl id="growl" showDetail="true" life="3000" autoUpdate="false" /> 
				        <h:panelGrid id="display" columns="4" cellpadding="4" width="100%">
				            
				            <p:outputLabel  value="Project Name" />
				            <p:inputText value="#{adviseUpdateBean.selectedDto.project.projectName}" disabled="true"/>
				            <p:outputLabel  value="Project Code" />
				            <p:inputText value="#{adviseUpdateBean.selectedDto.project.projectCode}"  disabled="true"/>		
				        
				 	        <p:outputLabel  value="Purchaser Name" />
				            <p:inputText value="#{adviseUpdateBean.selectedDto.customer.fullName}" disabled="true"/>
				             <p:outputLabel  value="Registration No." />
				            <p:inputText value="#{adviseUpdateBean.selectedDto.account.registrationNo}" disabled="true" style="width:35%"/>
	
				            <p:outputLabel  value="Block No" />
				            <p:inputText value="#{adviseUpdateBean.selectedDto.projectInvetory.blockNo}" disabled="true" style="width:35%"/>
				            <p:outputLabel  value="Level" />
				            <p:inputText value="#{adviseUpdateBean.selectedDto.projectInvetory.level}" disabled="true" style="width:35%"/>
				        
				            <p:outputLabel  value="Unit No" />
				            <p:inputText value="#{adviseUpdateBean.selectedDto.projectInvetory.unitNo}" disabled="true" style="width:35%"/>
				            <p:outputLabel  value="" />
				            <p:outputLabel  value="" />		
				            					           
				            <p:outputLabel  value="Advise Date" />
				            <p:calendar value="#{adviseUpdateBean.selectedDto.account.adviseSignedDate}" id="popupButtonCal1" 
				            	pattern="dd/MM/yyyy" showOn="button" style="width:50%" />
				            <h:panelGroup>	
					            <p:commandButton id="upBtn" update=":uploadForm" oncomplete="upDialog.show()" title="Upload" value="Upload"/>
					            <p:commandButton id="downBtn" update=":downloadForm" oncomplete="downDialog.show()" title="View" value="View"/>
				            </h:panelGroup>
				            <p:outputLabel  value="" />
				            
				            <p:outputLabel  value="Advise Accepted Date" />
				            <p:calendar value="#{adviseUpdateBean.selectedDto.account.adviseStampedDate}" id="popupButtonCal2" showOn="button" 
				            	pattern="#{adviseUpdateBean.dateFormat}"
				            	 style="width:50%" />
				            <p:outputLabel  value="" />
				            <p:outputLabel  value="" />	
				            
				            <p:outputLabel  value="Advise Update By" />
				            <p:inputText value="#{adviseUpdateBean.selectedDto.verifiedBy}" disabled="true" />
				            <p:outputLabel  value="Advise Update Date" />
				            <p:inputText  value="#{adviseUpdateBean.selectedDto.account.adviseVerifiedDate}" disabled="true" >
            						<f:convertDateTime type="both" locale="ms-my" pattern="#{adviseUpdateBean.dateFormat}" />
            				</p:inputText>  
				            		
				           				            	
				            				            			            
				            <p:outputLabel value=""/>
				            <p:commandButton value = "Close" actionListener="#{adviseUpdateBean.closeAdviseDetails}" ajax="true" partialSubmit="true" update="growl,:puListForm:resultsPanel" style="margin-top:20px;float:right"
							 oncomplete="handleSaveRequest(xhr, status, args)"/>					            			            
							<p:commandButton value = "Save" actionListener="#{adviseUpdateBean.saveAdviseDetails}" ajax="true" update="growl,:puListForm:resultsPanel" style="margin-top:20px"
							 oncomplete="handleSaveRequest(xhr, status, args)"/>
							 <p:outputLabel value=""/>				            				            			            
				        </h:panelGrid>				        
				    </p:dialog> 
				    <script type="text/javascript">  
						    function handleSaveRequest(xhr, status, args) {  
						        if(args.validationFailed || !args.success) {  
						            dlg.jq.effect("shake", { times:5 }, 100);
						            
						        }   
						        else {  
						        	dlg.hide();
						           // PF('dlg').hide();  
						           // $('#loginLink').fadeOut();  
						        }  
						    }
						    
						</script>  
				 </p:outputPanel> 
 	 	 	
 	 	 	</h:form>
 	 	 	<h:form id="uploadForm" enctype="mulipart/form-data">
 	 	 		<p:dialog id="uploadDialog" header="Upload" widgetVar="upDialog"
				        modal="true" height="250" width="700"  showEffect="explode"
				        hideEffect="explode">
				         <p:messages id="messages" showDetail="true" />
				        <p:growl id="growl12" showDetail="true" life="3000" autoUpdate="false" />
					    
						<p:fileUpload mode="advanced" style="width:95%"
							fileUploadListener="#{adviseUpdateBean.handleFileUpload}"  update="growl12,downloadDataTable2" 
							allowTypes="/(\.|\/)(doc|docx|pdf|xls|xlsx)$/"  />
							<br/>
							<p:dataTable id="downloadDataTable2" 
	                    			value="#{adviseUpdateBean.allUploadedFiles}"
	                    			var="file" widgetVar="downlaodFile"
	                    			emptyMessage="NO Files Uploaded"
	                    			style="width:95%; border:2 !important; border-color:white !important;">
	                    
	                    		<p:column>
	            					<f:facet name="header">
	                					Uploaded Files 
	            					</f:facet>
	             					<h:outputText value="#{file.name}" /> 
	        					</p:column>
	                		</p:dataTable>
					</p:dialog>
				</h:form>
				<h:form id="downloadForm" >
 	 	 		<p:dialog id="downloadDialog" header="View" widgetVar="downDialog"
				        modal="true" height="250" width="700"  showEffect="explode"
				        hideEffect="explode">
				        
				        <p:dataTable id="downloadDataTable" 
                    			value="#{adviseUpdateBean.allUploadedFiles}"
                    			var="file" widgetVar="downlaodFile"
                    			emptyMessage="NO Files Uploaded"
                    			style="width:95%; border:2 !important; border-color:white !important;">
                    
                    		<p:column>
            					<f:facet name="header">
                					File Name
            					</f:facet>
             					<h:outputText value="#{file.name}" /> 
        					</p:column>
                    <p:column headerText="Action">
                    
                    <p:commandButton id="downloadLink" value="Download" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"  update="growl12" 
        				icon="ui-icon-arrowthichk-s" actionListener="#{adviseUpdateBean.prepareFileToDownload(file)}">  
    					<p:fileDownload value="#{adviseUpdateBean.fileToDownload}" />  
					</p:commandButton>
                    </p:column>
                </p:dataTable>
					</p:dialog>
				</h:form>
		</p:panel>
 	 	</ui:define>
 	 </ui:composition>
 	 
 	 
 </body>
</html> 
